#include "widget.h"
#include "ui_widget.h"
#include "QTimer"
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //启动定时器，参数为毫秒级别
    id1=startTimer(1000);
    id2=startTimer(2000);
    //创建定时器对象
    QTimer *timer1=new QTimer(this);
    //设置定时器的值
    timer1->start(500);
    connect(timer1,&QTimer::timeout,[=](){
        static int i;
        ui->label_3->setText(QString::number(i++));
    });
    connect(ui->Btn1,&QPushButton::clicked,[=](){
        timer1->stop();
    });
}
void Widget::timerEvent(QTimerEvent *ev){
    static int num=1;
    static int num2=1;
    if(ev->timerId()==id1){
         ui->label->setText(QString::number(num++));
    }
    if(ev->timerId()==id2){
        ui->label_2->setText(QString::number(num2++));
    }


}
Widget::~Widget()
{
    delete ui;
}

